package com.asset.dispoal.file.feature.service.command;

import com.asset.dispoal.commom.page.PagingQuery;
import com.asset.dispoal.file.feature.domain.db.mapper.FileFeatureTableMapper;
import com.asset.dispoal.file.feature.dto.FileFeatureTablePageRequest;
import com.asset.dispoal.file.feature.dto.FileFeatureTablePageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

@Component
public class QueryPageFileFeatureTableCommand implements BaseCommand<FileFeatureTablePageRequest, Result<PageVO<FileFeatureTablePageResponse>>> {

    @Autowired
    FileFeatureTableMapper fileFeatureTableMapper;

    @Override
    public Result<PageVO<FileFeatureTablePageResponse>> execute(FileFeatureTablePageRequest request) {
        int count = fileFeatureTableMapper.queryPageCount(request);
        Page<FileFeatureTablePageRequest> page = PagingQuery.getPage(count, request);
        PageVO<FileFeatureTablePageResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            List<FileFeatureTablePageResponse> appointResponses = fileFeatureTableMapper.queryPage(page);
            pageVO.setResult(appointResponses);
        }
        return Result.ok(pageVO);
    }
}
